//
// Created by Administrator on 2019/12/10.
//
#include <iostream>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

/**
 * 创建子进程相关
 * @return
 */
void print1() {
//    int pid;
//    pid = fork();
//    cout << "hello world !! " << endl;
//
//    if (pid == 0) {
//        cout << "不好意思，我是子进程的打印 !" << endl;
//    } else {
//        cout << "哈哈，我是父进程的打印--" << pid << endl;
//    }

}

/**
 * 子进程测试
 * @return
 */
void print2() {
    cout << "print2 ----------------" << endl;
    int globa = 1;
    int pid, viso = 5;
//    pid = fork();
//    while (pid == -1);

    if (pid == 0) {
        globa++;
        viso--;
        printf("Child:globa=%d,viso=%d, pid=%d\n", globa, viso, pid);
        exit(0);
    } else {
        printf("Parent:globa=%d,viso=%d, pid=%d\n", globa, viso, pid);
    };
    cout << "print2 结束-->" << endl;

}

/**
 * 除法
 * @param x 除数
 * @param y 被除数
 * @return
 */
double division(double x, double y) {
    if(y == 0) {
        throw "Division by zero condition!";
    } else {
        return (x / y);
    }
}

// 测试异常相关
void print3(){
    cout << "print3 ----------------" << endl;

    int a = 50;
    int b = 0;
    int z;
    try {
        z = division(a, b);
    } catch (const char *msg) {
        cerr << msg << endl;
    }
}

class Line {
public:
    Line(char *name){
        this->name = name;
        cout << "调用Line()有参构造,name=" << name << endl;
    }
    Line(const Line &line){
        cout << "调用Line(&Line)拷贝构造函数" << endl;
        name = new char;
        *name = *line.name;
    }
    ~Line(){
        cout << "这是析构函数-xxxxxxx" << endl;
    }

    char *getName();

private:
    char *name;

};

char * Line::getName() {
    cout << this->name;
}


void display(Line &line) {
    cout << "line的名称是：" << line.getName() << endl;
}

/**
 * 测试拷贝构造函数
 */
void print4(){
    cout << "print4 ------------------------" << endl;
    Line line("hello world !!!");




}